echo "开始运行！"
if [ -e /opt/module/zookeeper/data ]; then
   rm -rf /opt/module/zookeeper/data
   echo "/opt/module/zookeeper/data,已删除"
fi
sudo mkdir -p /opt/module/zookeeper/data
echo "/opt/module/zookeeper/data,创建目录成功！"
if [ -e /opt/module/zookeeper/logs ]; then
   rm -rf /opt/module/zookeeper/logs
   echo "/opt/module/zookeeper/logs,已删除"
fi
sudo mkdir -p /opt/module/zookeeper/logs
echo "/opt/module/zookeeper/logs,创建目录成功！"
sudo chmod -R 755 /opt/module/zookeeper
if [ -e /opt/module/zookeeper ]; then
   rm -rf /opt/module/zookeeper
   echo "/opt/module/zookeeper,已删除"
fi
sudo mkdir -p /opt/module/zookeeper
echo "/opt/module/zookeeper,创建目录成功！"
zookeeper_tar=`find /opt/upload/software -name zookeeper-3.7.2*`
if [[ $zookeeper_tar == *"zookeeper-3.7.2"* ]]; then
    echo "zookeeper_tar = $zookeeper_tar"
else
    echo "zookeeper_tar，值为空,退出安装"
    exit 1
fi
tar -xzvf $jdk_tar -C /opt/module/zookeeper
cd /opt/module/zookeeper
zookeeper_install=`find /opt/module/zookeeper -name zookeeper-3.7.2*`
if [[ $zookeeper_install == *"zookeeper-3.7.2"* ]]; then
    echo "zookeeper_install = $zookeeper_install"
else
    echo "zookeeper_install，值为空,退出安装"
    exit 1
fi
echo "修改文件权限,755方便其他用户有权限执行"
sudo chmod -R 755 /opt/module/zookeeper
sudo echo "#环境变量" > /etc/profile.d/zookeeper_env.sh
sudo echo "export ZOOKEEPER_HOME=$hadoop_install" >> /etc/profile.d/zookeeper_env.sh
sudo echo "export PATH=\$PATH:\$ZOOKEEPER_HOME/bin" >> /etc/profile.d/zookeeper_env.sh
#环境变量生效
cat /etc/profile.d/zookeeper_env.sh
source /etc/profile
echo "设置Zookeeper的myid"
echo "3" > /opt/module/zookeeper/data/myid
# 防火墙配置
echo "防火墙允许2181,2888,3888端口通过"
sudo firewall-cmd --add-port=2181/tcp --permanent
sudo firewall-cmd --add-port=2888/tcp --permanent
sudo firewall-cmd --add-port=3888/tcp --permanent
sudo firewall-cmd --reload
echo "运行结束！"